package com.java.web;

import com.java.bean.Student;
import com.java.service.StudentService;
import com.java.service.impl.StudentServiceImpl;
import com.java.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: wjr
 * @Description:
 * @Date Created in  2020-09-07 0:41
 * @Modified By:
 */
@WebServlet(value = {"/addStudent"})
public class AddStudentServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String studnetno = req.getParameter("studnetno");
        String studentname = req.getParameter("studentname");
        int studentage = Integer.parseInt(req.getParameter("studentage"));
        int gradeid = Integer.parseInt(req.getParameter("gradeid"));
        Student student = new Student(studnetno, studentname, studentage, gradeid);
        System.out.println(student.toString());
        StudentService studentService = new StudentServiceImpl();
        ResponseUtils responseUtils = new ResponseUtils();
        boolean b = studentService.addStudent(student);
        String msg = "";
        if (b){
            msg = "操作成功";
        }else {
            msg = "操作失败";
        }
        responseUtils.ResponseMsg(resp,msg,"/showAll");
    }
}
